<?php
namespace Home\Controller;
use Lib\Alidayu\SendSMS;
class UserController extends CommonController {

	public function _initialize()
	{
		$this->Is_login();        //检测用户登录信息,如果错误直接返回错误,终止程序
		$this->Is_power("member");        //检测用户权限,如果错误直接返回错误,终止程序
		$this->assign('heardadminData',session('heardadminData'));
		$db_member = M("member");
		$db_data = M("data");
		$db_broadcasttime = M("broadcasttime");
	}


	//主播列表
	public function user_list()
	{
		$db_member = M("member m");
		// $labelkey = I('get.labelkey');
		$this->p = I('get.p')?I('get.p'):1;
		$authkey = I('get.authkey');
		$sex = I('get.sex');
		$soundtype = I('get.soundtype');
		$select_wx = I('get.select_wx');
		$user_name = I('get.user_name');
		$levelkey = I('get.levelkey');
		// $mediakey = I('get.mediakey');
		// $this->labelkey = $labelkey;
		$this->authkey = $authkey;
		$this->user_name = $user_name;
		$this->levelkey = $levelkey;
		$this->sex = $sex;
		$this->soundtype = $soundtype;
		$this->select_wx = $select_wx;
		// $this->mediakey = $mediakey;
		$where = " 1=1 ";
		if (!empty($user_name)) {$where .= " and (m.nickname like '%$user_name%' or m.uuid like '%$user_name%' or m.username like '%$user_name%')";}
		// if (!empty($labelkey)) {$where .= " and (articles like '%$labelkey%')";}
		switch ($authkey) {
			case '1':$where .= " and m.authentication = 1";break;
			case '2':$where .= " and m.authentication = 0";break;
		}
		switch ($select_wx) {
			case '1':$where .= " and openid != ''";break;
			case '2':$where .= " and openid = ''";break;
		}
		switch ($sex) {
			case '1':$where .= " and m.sex = 1";break;
			case '2':$where .= " and m.sex = 2";break;
		}
		$leveldatadesc = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
		if (!empty($levelkey)) {
			foreach ($leveldatadesc as $key1 => $value1) {
				if ($levelkey == $value1['id']) {
					if ($key1 == 0) {
						$where .= " and level >=$value1[value]";
					}else{
						$last_value = $leveldatadesc[$key1-1]['value'];
						$where .= " and level >=$value1[value] and level < $last_value";
					}
				}
			}
		}
		if(!empty($soundtype)){
			$soundtype_arr = explode(',',$soundtype);
			foreach ($soundtype_arr as $v){
				switch ($v){
					case 1: $where .= " and m.soundtype like '%0%'";break;
					case 2: $where .= " and soundtype like '%1%'";break;
					case 3: $where .= " and m.soundtype like '%2%'";break;
					case 4: $where .= " and soundtype like '%3%'";break;
					case 5: $where .= " and soundtype like '%4%'";break;
					case 6: $where .= " and soundtype like '%5%'";break;
					case 7: $where .= " and is_bgm = 2";break;
				}
			}
		}
		/*$medialist = $db_media->field('id,media_name')->where(array("collectpower"=>1))->select();
		if (!empty($mediakey)) {
			$collectuser = $db_media->field('uuid')->where(array("id"=>$mediakey))->find()['uuid'];
			if ($collectuser) {
				$where .= " and uuid = $collectuser";
			}else{
				$where .= " and uuid = 0";
			}
		}
*/
		// echo $where;exit();
		$count = $db_member->where(array('status'=>9))->field('m.*')->where($where)->join('__WECHAT__ w on w.uuid = m.uuid','left')->count();
		$p = getpage($count, 20);
		$userinfo = $db_member->where(array('status'=>9))->field('m.*')->where($where)->join('__WECHAT__ w on w.uuid = m.uuid','left')->limit($p->firstRow, $p->listRows)->select();
		$leveldata = M("systemsetup")->where(array("type"=>1))->order('value asc')->select();
		// $labeldata = M("label")->select();//读取配置
		foreach ($userinfo as $key2 => &$value2) {
			foreach ($leveldata as $k => $v) {
				if($value2['level'] >= $v['value']){$value2['level_type'] = $v['message'];}
			}
			/*$value2['articles'] = explode(",", $value2['articles']);
			// p($value2['articles']);exit();
			foreach ($labeldata as $k1 => $v1) {
				foreach ($value2['articles'] as $k2 => $v2) {
					if($v1['label_id'] == $v2){$value2['articles_arr'][] = $v1['label_name'];}
				}
			}
			$value2['articles_arr'] = implode(",", $value2['articles_arr']);
			// 绑定的自媒体
			$cmediadata = M('media')->field('media_name')->where("uuid = $value2[uuid]")->select();
			foreach ($cmediadata as $k3 => $v3) {
				$value2['mediadata'][] = $v3['media_name'];
			}
			if (empty($cmediadata)) {
				$value2['mediadata'][0] = "无";
			}
			$value2['mediadata'] = implode(",", $value2['mediadata']);*/
			// 当前用户邀请数量
			$value2['invitecount'] = M('invite')->where(array('inviteid'=>$value2['uuid']))->count();
			// 已完成订单数量
			$value2['ordernum'] = M('order')->field('id')->where(array('user_id'=>$value2['uuid'],'status'=>8))->count();
			// 邀请人
			$inviteid = M('invite')->field('inviteid')->where(array('uuid'=>$value2['uuid']))->find()['inviteid'];
			$value2['invite_nickname'] = $db_member->where(array('uuid'=>$inviteid))->field('nickname')->find()['nickname'];
			if (empty($value2['invite_nickname'])) {
				$value2['invite_nickname'] = "无";
			}
			$value2['openid'] = M('wechat')->where(array('uuid'=>$value2['uuid']))->field('openid')->find()['openid'];

		}
		// p($userinfo);
		// 根据时间段再次筛选
		/*if (!empty($mediakey)) {
			$this->media_name = $db_media->field('media_name')->where("id=$mediakey")->find()['media_name'];
			$user_data = $userinfo;
		}else{
			$user_data = $userinfo;
		}*/
		// p($user_data);exit();

		$page = $p->show();
		// 获取查询参数
		$map['user_name'] = empty($user_name)?"":$user_name;
		// $map['labelkey'] = $labelkey;
		$map['levelkey'] = $levelkey;
		$map['authkey'] = $authkey;
		$map['sex'] = $sex;
		$map['soundtype'] = "123";//(string)implode('',$soundtype);
//		foreach($soundtype as $so){
//			$map['soundtype'] .=$so;
//		}
//		$map['soundtype'] = 123;//(string)$map['soundtype'];
		$map['select_wx'] = $select_wx;
		// $map['mediakey'] = $mediakey;
		$p->parameter = "";
		foreach($map as $key=>$val) {
				$p->parameter .= "$key=".urlencode($val)."&";
		}
		$user = explode(",", cookie('heardadminPower'));
		if(in_array('add_del', $user)||cookie('founder')==1){
			$add_del = 1;//是否有加钱权限
		}
		$this->assign('add_del',$add_del);
		$this->assign('userinfo',$userinfo);
		// $this->assign('labeldata',$labeldata);
		$this->assign('leveldatadesc',$leveldatadesc);
		// $this->assign('medialist',$medialist);
		/*$this->assign('mediacollect',$mediacollect);*/
		$this->assign('page', $page);
		$this->display();
	}

	//主播列表
	public function user_order()
	{
		// p($_POST);exit();
		$db_order = M("order");
		$uuid = I('uuid');
		$order_name = I('order_name');
		$this->uuid = $uuid;
		$this->labelkey = $labelkey;
		$this->order_name = $order_name;
		$this->levelkey = $levelkey;
		$where = "user_id = $uuid ";
		if (!empty($labelkey)) {$where .= " and `texttype` = \"".$labelkey."\" ";}
		if (!empty($levelkey)) {$where .= " and `level` = \"".$levelkey."\" ";}
		if (!empty($order_name)) {$where .= " and (media_name like '%$order_name%' or id like '%$order_name%' or title like '%$order_name%')";}
		// echo $where;exit();
		$count = $db_order->where($where)->order('id desc')->count();
		$p = getpage($count, 20);
		$orderinfo = $db_order->where($where)->order('id desc')->limit($p->firstRow, $p->listRows)->select();
		// $leveldata = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
		$labeldata = M("label")->select();//读取配置
		foreach ($orderinfo as $key => &$value) {
			// foreach ($leveldata as $k => $v) {
			// 	if($value['level'] == $v['id']){$value['level_type'] = $v['message'];}
			// }
			$value['usemoney'] = $value['price'];
			if ($value['requirement'] == 3) {
				$value['usemoney'] = $value['price']+$value['increase_price'];
			}
			if ($value['bgm_id'] != 0) {
				$value['usemoney'] = $value['usemoney']+10;
			}
			$value['usemoney'] = sprintf('%.2f', $value['usemoney']);
		}
		// p($orderinfo);exit();
		$this->assign('orderinfo',$orderinfo);
		$this->assign('labeldata',$labeldata);
		// $this->assign('leveldata',$leveldata);
		$this->assign('page', $p->show());
		$this->display();
	}
	public function user_signorder()
	{
		// p($_POST);exit();
		$db_order = M("order");
		$uuid = I('uuid');
		$order_name = I('order_name');
		$this->uuid = $uuid;
		$attribute = I('get.attribute');
		$this->attribute = $attribute;
		$this->order_name = $order_name;
		$where = "uuid = $uuid and (state=3 or state=4) and attribute=1 ";
		if (!empty($order_name)) {$where .= " and (mname like '%$order_name%' or number like '%$order_name%' or title like '%$order_name%')";}
		// echo $where;exit();
		$count = $db_order->where($where)->order('id desc')->count();
		$p = getpage($count, 20);
		$orderlist = $db_order->where($where)->field("id,title,audio_link,audio_upload_time")->order('id desc')->limit($p->firstRow, $p->listRows)->select();
		foreach ($orderlist as $key => &$value) {
			$value['durationtime'] = (int)json_decode(do_curl($value['audio_link'].'?avinfo'),true)['format']['duration'];
			$value['durationtime'] = date("i:s",$value['durationtime']);
		}
		// p($orderlist);exit();
		$this->assign('orderlist',$orderlist);
		$this->assign('page', $p->show());
		$this->display();
	}
	//主播详情
	public function user_message()
	{
		$this->p = I('get.p');
		$this->authkey = I('get.authkey');
		$uid = I('get.uid');
		$db_member = M("member");
		$db_broadcasttime = M("broadcasttime");
		$db_data = M("data");
		$db_media = M("media");
		$userdata = $db_member->where(array('status'=>9,'id'=>$uid))->find();
		$userdata['articles'] = explode(",", $userdata['articles']);

		$userdata['voicetype'] = explode(",", $userdata['voicetype']);
		foreach ($userdata['voicetype'] as $key => &$value) {
			$value = substr(substr($value,1),0,-1);
		}
		$labeldata = M("label")->select();//读取配置
		$leveldata = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
		$this->article_num = M("systemsetup")->where("id=1")->find()['value'];
		$this->voicetype_num = M("systemsetup")->where("id=2")->find()['value'];
		$medialist = $db_media->field('id,media_name,uuid')->select();
		$uservoice = $db_data->where(array('uuid'=>$userdata['uuid']))->find();
		$userdata['name'] = M('authentication')->where(array('uuid'=>$userdata['uuid'],'type'=>1))->order('id desc')->find()['name'];
		$userdata['agelabel'] = $this->Parameterexplode($userdata['agelabel']);
		$userdata['feellabel'] = $this->Parameterexplode($userdata['feellabel']);
		$userdata['stylelabel'] = $this->Parameterexplode($userdata['stylelabel']);
		// p($userdata);
		// exit();
		$this->agelabeldata = M("userlabel")->where(array("type"=>1))->select();
		$this->feellabeldata = M("userlabel")->where(array("type"=>2))->select();
		$this->stylelabeldata = M("userlabel")->where(array("type"=>3))->select();
		$user = explode(",", cookie('heardadminPower'));
		if(in_array('add_del', $user)||cookie('founder')==1){
			$add_del = 1;//是否有加钱权限
		}
		$this->assign('add_del',$add_del);
		$this->assign('userdata',$userdata);
		$this->assign('uservoice',$uservoice);
		$this->assign('labeldata',$labeldata);
		$this->assign('leveldata',$leveldata);
		$this->assign('medialist',$medialist);
		$this->display();
	}
	//修改主播信息
	public function user_edit()
	{
		// p($_POST);exit();
		$uuid = I('post.uuid');
		$data['name'] = I('post.name');
		$data['nickname'] = I('post.nickname');
		$data['username'] = I('post.username');
		$data['sex'] = I('post.sex');
		$data['birthdate'] = I('post.birthdate');
		$data['city'] = I('post.city');
		$data['education'] = I('post.education');
		$data['english'] = I('post.english');
		$data['profession'] = I('post.profession');
		$data['is_show'] = I('post.is_show');
		$articles = I('post.articles');
		$p = I('post.p');
		$authkey = I('post.authkey');

		$data['articles'] = implode(",", $articles);
		$agelabel = I('post.agelabel');
		$feellabel = I('post.feellabel');
		$stylelabel = I('post.stylelabel');
		/*$voicetype = I('post.voicetype');
		foreach ($voicetype as $key => &$value) {
			$value = "-".$value."-";
		}
		$data['voicetype'] = implode(",", $voicetype);*/
		$soundtype = I('post.soundtype');
		foreach ($soundtype as $key => &$value) {
			$soundvalue[] = $key;
		}
		$data['soundtype'] = implode(",", $soundvalue);
		$data['level'] = I('post.level');
		$data['agelabel'] = NULL;
		$data['feellabel'] = NULL;
		$data['stylelabel'] = NULL;
		if ($agelabel) {
			$data['agelabel'] = $this->Parameterimplode($agelabel);
		}
		if ($feellabel) {
			$data['feellabel'] = $this->Parameterimplode($feellabel);
		}
		if ($stylelabel) {
			$data['stylelabel'] = $this->Parameterimplode($stylelabel);
		}
		$soundtype['5']?$data['is_introduction']=2:$data['is_introduction']=3;
		$audio['age'] = $data['agelabel'];
		$audio['style'] = trim($data['feellabel'].','.$data['stylelabel'],',');
		M('audio')->where(array('uuid'=>$uuid))->save($audio);//更新audio中数据
		M("member")->where(array('uuid'=>$uuid))->save($data);//更新数据
		M('audio')->where(['uuid'=>$uuid])->save(['cid'=>$data['soundtype']]);
		$soundtype['0']?$data2['describe_audio_type']=1:$data2['describe_audio_type']=0;
		$soundtype['1']?$data2['emotion_audio_type']=1:$data2['emotion_audio_type']=0;
		$soundtype['2']?$data2['variety_audio_type']=1:$data2['variety_audio_type']=0;
		$soundtype['3']?$data2['news_audio_type']=1:$data2['news_audio_type']=0;
		$soundtype['4']?$data2['english_audio_type']=1:$data2['english_audio_type']=0;
		$soundtype['5']?$data2['introduction_audio_type']=1:$data2['introduction_audio_type']=0;
		// p($data2);exit();
		M("data")->where(array('uuid'=>$uuid))->save($data2);//更新数据
		$soundtype['0']?"":$this->add_verify_log($uuid,"",1);
		$soundtype['1']?"":$this->add_verify_log($uuid,"",2);
		$soundtype['2']?"":$this->add_verify_log($uuid,"",3);
		$soundtype['3']?"":$this->add_verify_log($uuid,"",4);
		$soundtype['5']?"":$this->add_verify_log($uuid,"",9);
		// p($data3);exit();

		$this->adminlog("修改主播信息".$uuid);
		$this->success('修改成功',"/Home/User/user_list?p=".$p."&authkey=".$authkey,1);
	}
	//主播扣钱
	public function user_deduct()
	{
		$this->Is_power("add_del");
		$data['uuid'] = I('uuid');
		$res = M("member")->where($data)->find();
		if ($res) {
			$income['time'] = time();
			$income['type'] = 6;
			$income['uuid'] = $data['uuid'];
			$income['amount'] = sprintf("%.2f",I('deductmoney'));
			$income['status'] = 1;
			$income['note'] = I('note');
			M("income")->add($income);//更新数据
			M("member")->where($data)->setDec("income",I('deductmoney'));//更新数据
			M("member")->where($data)->setDec("balance",I('deductmoney'));//更新数据
			$this->adminlog("主播".$data['uuid']."扣除".I('deductmoney'));
			$this->success('扣钱成功',"/Home/User/user_list",1);
		}else{
		  $this->error('主播不存',"",1);
		}
	}
	//收藏主播
	public function user_binding()
	{
		$data['uuid'] = I('uuid');
		$data['authentication'] = 1;
		$res = M("member")->where($data)->find();
		if ($res) {
			$media['id'] = I('mediaid');
			$media_info = M("media")->where($media)->find();
			if(!$media_info['signtimelimit']){
				$this->error('请补全自媒体资料',"",1);
			}
			M("media")->where($media)->save($data);//更新数据
			$add['wid'] = I('mediaid');
			$add['old_uuid'] = $media_info['uuid'];
			$add['new_uuid'] = $data['uuid'];
			$add['add_time'] = time();
			M("signmemberlog")->add($add);//添加更换主播记录
			$this->adminlog($media['id']."签约主播".$data['uuid']);
			$this->success('签约成功',"",1);
		}else{
		  $this->error('主播不存在或未认证',"",1);
		}
	}
	//删除主播
	public function user_delete()
	{
		$password = I('post.password');
		if (empty($password)||$password!="Heard123456") {
			$this->error('密码错误',"",1);
		}else{
			$uuid = I('post.uuid');
			$tel = I('post.tel');
			$name = I('post.name');
			if ($uuid == "100001") {
				$this->error('不可删除',"/Home/User/user_list",1);
			}else{
				if (empty($uuid)) {
					$this->error('参数错误',"",1);
				}else{
					// $this->error('暂不可删除',"/Home/User/user_list",1);
					// exit();
					M()->startTrans();
					$res_member = M("member")->where("uuid=$uuid")->delete();
					/*$res_data = M("data")->where("uuid=$uuid")->delete();
					$res_wechat = M("wechat")->where("uuid=$uuid")->delete();
					M("broadcasttime")->where("uuid=$uuid")->delete();
					M("authentication")->where("uuid=$uuid")->delete();
					M("drawmoney")->where("uuid=$uuid")->delete();
					M("income")->where("uuid=$uuid")->delete();
					M("order")->where("uuid=$uuid")->delete();
					M("orderverify")->where("uuid=$uuid")->delete();
					M("signjoin")->where("uuid=$uuid")->delete();
					M("balance")->where("uuid=$uuid")->delete();
					M("drawmoney")->where("uuid=$uuid")->delete();
					M("invite")->where("uuid=$uuid")->delete();
					M("invite")->where("inviteid=$uuid")->delete();
					M("score")->where("uuid=$uuid")->delete();
					M("musictime")->where("uuid=$uuid")->delete();*/
					// M("media")->where(array('uuid'=>$uuid))->save(array('uuid'=>""));//更新数据
					// if($res_member&&$res_data&&$res_wechat){
					if($res_member){
						M()->commit();
						$this->adminlog("删除主播".$uuid.$name.$tel);
						$this->success('删除成功',"/Home/User/user_list",1);
					}else{
						M()->rollback();
						$this->error('删除失败',"/Home/User/user_list",1);
					}
				}
			}
		}
	}
	//给主播加分
	public function add_score()
	{
		$where['uuid'] = I('post.uuid');
		$score = I('post.addscore');
		$res = M("member")->where($where)->find();
		if ($res) {
			M("member")->where($where)->setInc('score',$score);// 加信用分
			$this->adminlog("给主播".$where['uuid']."加".$score."信用分");
			$this->success('添加成功',"/Home/User/user_list",1);
		}else{
		  $this->error('主播不存在',"",1);
		}
	}
	//给主播加钱
	public function add_balance()
	{
		$this->Is_power("add_del");
		$where['uuid'] = I('post.uuid');
		$money = I('post.addmoney');
		$note = I('post.note');
		$res = M("member")->where($where)->find();
		if ($res) {
			M("member")->where($where)->setInc('income',$money);// 加余额
			M("member")->where($where)->setInc('balance',$money);// 加余额
			M('income')->add(array('time'=>time(),'type'=>4,'uuid'=>$where['uuid'],'oid'=>1,'amount'=>$money,'status'=>1,'note'=>$note));
			$this->adminlog("给主播".$where['uuid']."加".$money."元");
			$this->success('添加成功',"/Home/User/user_list",1);
		}else{
		  $this->error('主播不存在',"",1);
		}
	}

	public function memberAlidayu($tel="13091718183",$Code='SMS_72800028',$name)
	{
		$alidayu = new SendSMS();
		$result = $alidayu->send($recNum=$tel,$smsParam='{"name":"'.$name.'"}',$smsTemplateCode=$Code,$smsFreesignName='听说Heard');
		// p($result);
	}
	public function inviteAlidayu($tel="13091718183",$Code='SMS_72800028',$name,$num)
	{
		$alidayu = new SendSMS();
		$result = $alidayu->send($recNum=$tel,$smsParam='{"name":"'.$name.'","num":"'.$num.'"}',$smsTemplateCode=$Code,$smsFreesignName='听说Heard');
		// p($result);
	}


	// 邀请人列表
	public function user_invite()
	{
		$uid = I('get.uid');
		$data = M('invite i')
		->join("__MEMBER__ m ON i.uuid = m.uuid")
		->where(array('i.inviteid'=>$uid))
		->select();
		foreach ($data as &$vo) {
			switch ($vo['status']) {
				case 1:
					$vo['status'] = '未完成注册';
					break;
				case 5:
					$vo['status'] = '审核驳回';
					break;
				case 8:
					$vo['status'] = '审核中';
					break;
				case 9:
					$vo['status'] = '通过审核';
					break;
			}
			if ($vo['level'] > 80) {
				$vo['level'] = '(A)'.$vo['level'];
			}else if ($vo['level'] > 50) {
				$vo['level'] = '(B)'.$vo['level'];
			}else if ($vo['level'] > 10) {
				$vo['level'] = '(C)'.$vo['level'];
			}else{
				$vo['level'] = ' ';
			}
			$vo['sex'] = $vo['sex'] == 1 ? '男' : '女';
			$vo['authentication'] = $vo['authentication'] == 1 ? '已认证' : '未认证';
		}
		$this->assign('data',$data);
		$this->display();
	}


	//派单主播列表
	public function sendmember_list()
	{
		// p($_GET);//exit();
		$db_sendmember = M("sendmember a");
		$user_name = I('get.user_name');
		$where = " 1=1 and a.status=1 ";
		$field = 'a.id,a.uuid,a.sendswitch,a.sendswitchtime,a.getorder,a.getsendnum,m.nickname,m.username';
		$this->user_name = $user_name;
		if (!empty($user_name)) {$where .= " and (m.nickname like '%$user_name%' or a.uuid like '%$user_name%' or m.username like '%$user_name%')";}
		$count = $db_sendmember->join('__MEMBER__ m ON m.uuid = a.uuid')->where($where)->count();
		$p = getpage($count, 20);
		$sendmemberlist = $db_sendmember->join('__MEMBER__ m ON a.uuid = m.uuid')->where($where)->field($field)->order("sendswitch=1 desc,getorder=1 desc,getsendnum desc,sendswitchtime asc")->limit($p->firstRow, $p->listRows)->select();
		$date = date("Ymd",time());
		foreach ($sendmemberlist as $key => &$value) {
			$value['num'] = M("sendverify")->where(array("date"=>$date,"uuid"=>$value['uuid']))->order("num desc")->find()['num'];
		}
		$page = $p->show();
		// 获取查询参数
		$map['user_name'] = empty($user_name)?"":$user_name;
		$p->parameter = "";
		foreach($map as $key=>$val) {
				$p->parameter .= "$key=".urlencode($val)."&";
		}
		$this->switchcount = $db_sendmember->join('__MEMBER__ m ON m.uuid = a.uuid')->where($where)->where(array("sendswitch"=>1))->count();
		$this->getordercount = $db_sendmember->join('__MEMBER__ m ON m.uuid = a.uuid')->where($where)->where(array("sendswitch"=>1,"getorder"=>0))->count();
		$this->allswitchcount = $db_sendmember->join('__MEMBER__ m ON m.uuid = a.uuid')->where($where)->count();
		$this->assign('sendmemberlist',$sendmemberlist);
		$this->assign('page', $page);
		$this->display();
	}
	/*public function sendmember_add()
	{
		// p($_POST);exit();
		$uuiddata = I('post.uuid');
		$uuiddata = str_replace(array("，","-"," "),array(",",",",","),$uuiddata);
		$db_sendmember = M("sendmember");
		$db_member = M("member");
		$uuiddata = explode(",", $uuiddata);
		$userdata = "";
		foreach ($uuiddata as $key => $uuid) {
			$user1 = $db_sendmember->where(array("uuid"=>$uuid))->find();
			$user2 = $db_member->where(array("uuid"=>$uuid,"authentication"=>1))->find();
			if(!$user1&&$user2){
				$this->sendAlidayu($user2['username'],"SMS_125885165");
				$db_sendmember->add(array("uuid"=>$uuid));
			}else{
				$userdata .= $uuid.",";
			}
		}
		if ($userdata != "") {
			echo "<script>alert('以下主播未能添加成功：".$userdata."')</script>";
		}
		$this->success('添加成功',"/Home/User/sendmember_list",1);
	}*/

//派单主播样音列表
	public function sendmemberaudio_list()
	{
		// p($_GET);//exit();
		$db_sendmember = M("sendmember a");
		$user_name = I('get.user_name');
		$where = " 1=1 ";
		$field = 'a.uuid,m.sex,m.nickname,m.username,(select audio_link from db_order t where t.user_id = a.uuid and (t.status=6 or t.status=8) and t.type!=3 order by id desc limit 1) orderaudio,(select audio_link from db_order t where t.user_id = a.uuid and (t.status=6 or t.status=8) and t.type=3 order by id desc limit 1) sendorderaudio';
		$this->user_name = $user_name;
		if (!empty($user_name)) {$where .= " and (m.nickname like '%$user_name%' or a.uuid like '%$user_name%' or m.username like '%$user_name%')";}
		$count = $db_sendmember->join('__MEMBER__ m ON a.uuid = m.uuid')->where($where)->field($field)->count();
		$p = getpage($count, 20);
		$sendmemberlist = $db_sendmember->join('__MEMBER__ m ON a.uuid = m.uuid')->where($where)->field($field)->limit($p->firstRow, $p->listRows)->select();
		$page = $p->show();
		// 获取查询参数
		$map['user_name'] = empty($user_name)?"":$user_name;
		$p->parameter = "";
		foreach($map as $key=>$val) {
				$p->parameter .= "$key=".urlencode($val)."&";
		}
		// p($sendmemberlist);
		$this->assign('sendmemberlist',$sendmemberlist);
		$this->assign('page', $page);
		$this->display();
	}

	//主播样音列表
	public function selectuser_list()
	{
		// p($_GET);exit();
		$db_member = M("member");
		$db_media = M("media");
		$sex = I('get.sex');
		$user_name = I('get.user_name');
		$levelkey = I('get.levelkey');
		$soundtype = I('get.soundtype');
		$this->sex = $sex;
		$this->levelkey = implode(",",$levelkey);
		$this->user_name = $user_name;
		$this->soundtype = implode(",",$soundtype);
		$where = " 1=1 ";
		if (!empty($sex)&&$sex!=0) {$where .= " and `sex` = ".$sex." ";}
		if (!empty($soundtype)) {
			foreach ($soundtype as $key => $value) {
				if ($value==0) {
					$where .= " and soundtype like '%$value%'";
				}
				if ($value==1) {
					$where .= " and soundtype like '%$value%'";
				}
				if ($value==2) {
					$where .= " and soundtype like '%$value%'";
				}
				if ($value==3) {
					$where .= " and soundtype like '%$value%'";
				}
			}
		}
		$leveldatadesc = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
		// p($levelkey);exit();
		if (!empty($levelkey)) {
			$where .= " and (";
			$level="";
			foreach ($levelkey as $key => $val) {
				if ($val==1) {
					$level .= " (level >=".$leveldatadesc['0']['value'].") or ";
				}
				if ($val==2) {
					$level .= " (level >=".$leveldatadesc['1']['value']." and level < ".$leveldatadesc['0']['value'].") or ";
				}
				if ($val==3) {
					$level .= " (level >=".$leveldatadesc['2']['value']." and level < ".$leveldatadesc['1']['value'].") or ";
				}
			}
			$level = substr($level, 0, -3);
			$where .= $level." )";
		}
		if (!empty($user_name)) {$where .= " and (nickname like '%$user_name%' or uuid like '%$user_name%' or username like '%$user_name%')";}
		// echo $where;exit();
		$count = $db_member->where(array('status'=>9))->where($where)->count();
		$p = getpage($count, 20);
		$userinfo = $db_member->where(array('status'=>9))->where($where)->limit($p->firstRow, $p->listRows)->select();
		$leveldata = M("systemsetup")->where(array("type"=>1))->order('value asc')->select();
		foreach ($userinfo as $key2 => &$value2) {
			foreach ($leveldata as $k => $v) {
				if($value2['level'] >= $v['value']){$value2['level_type'] = $v['message'];}
			}
			// $value2['linkaudio'] = M('order')->where(array("uuid"=>$value2['uuid']))->where("state=3 or state=4")->order("id desc")->find()['linkaudio'];
		}
		// p($userinfo);exit();
		$page = $p->show();
		// 获取查询参数
		$map['user_name'] = empty($user_name)?"":$user_name;
		$map['labelkey'] = $labelkey;
		$map['levelkey'] = $levelkey;
		$p->parameter = "";
		foreach($map as $key=>$val) {
				$p->parameter .= "$key=".urlencode($val)."&";
		}
		$this->assign('userinfo',$userinfo);
		$this->assign('leveldatadesc',$leveldatadesc);
		$this->assign('page', $page);
		$this->display();
	}
	//主播复审列表
	public function selectreview_list()
	{
		// p($_GET);exit();
		$db_member = M("member");
		$db_media = M("media");
		$sex = I('get.sex');
		$user_name = I('get.user_name');
		$levelkey = I('get.levelkey');
		$soundtype = I('get.soundtype');
		$this->sex = $sex;
		$this->levelkey = implode(",",$levelkey);
		$this->user_name = $user_name;
		$this->soundtype = implode(",",$soundtype);
		$where = " 1=1 ";
		if (!empty($sex)&&$sex!=0) {$where .= " and `sex` = ".$sex." ";}
		if (!empty($soundtype)) {
			foreach ($soundtype as $key => $value) {
				if ($value==0) {
					$where .= " and soundtype like '%$value%'";
				}
				if ($value==1) {
					$where .= " and soundtype like '%$value%'";
				}
				if ($value==2) {
					$where .= " and soundtype like '%$value%'";
				}
				if ($value==3) {
					$where .= " and soundtype like '%$value%'";
				}
			}
		}
		$leveldatadesc = M("systemsetup")->where(array("type"=>1))->order('value desc')->select();
		// p($levelkey);exit();
		if (!empty($levelkey)) {
			$where .= " and (";
			$level="";
			foreach ($levelkey as $key => $val) {
				if ($val==1) {
					$level .= " (level >=".$leveldatadesc['0']['value'].") or ";
				}
				if ($val==2) {
					$level .= " (level >=".$leveldatadesc['1']['value']." and level < ".$leveldatadesc['0']['value'].") or ";
				}
				if ($val==3) {
					$level .= " (level >=".$leveldatadesc['2']['value']." and level < ".$leveldatadesc['1']['value'].") or ";
				}
			}
			$level = substr($level, 0, -3);
			$where .= $level." )";
		}
		if (!empty($user_name)) {$where .= " and (nickname like '%$user_name%' or uuid like '%$user_name%' or username like '%$user_name%')";}
		// echo $where;exit();
		$count = $db_member->where(array('status'=>9,'is_introduction'=>2))->where($where)->count();
		$p = getpage($count, 20);
		$userinfo = $db_member->where(array('status'=>9,'is_introduction'=>2))->where($where)->limit($p->firstRow, $p->listRows)->select();
		$leveldata = M("systemsetup")->where(array("type"=>1))->order('value asc')->select();
		foreach ($userinfo as $key2 => &$value2) {
			foreach ($leveldata as $k => $v) {
				if($value2['level'] >= $v['value']){$value2['level_type'] = $v['message'];}
			}
			// $value2['linkaudio'] = M('order')->where(array("uuid"=>$value2['uuid']))->where("state=3 or state=4")->order("id desc")->find()['linkaudio'];
		}
		// p($userinfo);exit();
		$page = $p->show();
		// 获取查询参数
		$map['user_name'] = empty($user_name)?"":$user_name;
		$map['levelkey'] = $levelkey;
		$p->parameter = "";
		foreach($map as $key=>$val) {
			$p->parameter .= "$key=".urlencode($val)."&";
		}
		$this->assign('userinfo',$userinfo);
		$this->assign('leveldatadesc',$leveldatadesc);
		$this->assign('page', $page);
		$this->display();
	}
	public function selectuser_message()
	{
		$uuid = I('get.uuid');
		$db_order = M("order");
		$where['user_id'] = $uuid;
		$audiodata[] = $db_order->where($where)->where("category=1 and (status=6 or status=8)")->order("id desc")->find()['audio_link'];
		$audiodata[] = $db_order->where($where)->where("category=2 and (status=6 or status=8)")->order("id desc")->find()['audio_link'];
		$audiodata[] = $db_order->where($where)->where("category=3 and (status=6 or status=8)")->order("id desc")->find()['audio_link'];
		$audiodata[] = $db_order->where($where)->where("category=4 and (status=6 or status=8)")->order("id desc")->find()['audio_link'];
		// p($audiodata);exit();
		foreach($audiodata as &$v){
			$v = url_add_domainname($v);
		}
		$this->assign('audiodata',$audiodata);
		$this->display();
	}
	public function selectreview_message()
	{
		$uuid = I('get.uuid');
		$where['uuid'] = $uuid;
		$audiodata = M('data')->field('describe_audio,emotion_audio,variety_audio,news_audio,english_audio,introduction_audio')->where($where)->find();
		$audiodata['describe_audio'] =$audiodata['describe_audio']?url_add_domainname($audiodata['describe_audio']):'';
		$audiodata['emotion_audio'] = $audiodata['emotion_audio']?url_add_domainname($audiodata['emotion_audio']):'';
		$audiodata['variety_audio'] = $audiodata['variety_audio']?url_add_domainname($audiodata['variety_audio']):'';
		$audiodata['news_audio'] = $audiodata['news_audio']?url_add_domainname($audiodata['news_audio']):'';
		$audiodata['english_audio'] = $audiodata['english_audio']?url_add_domainname($audiodata['english_audio']):'';
		$audiodata['introduction_audio'] = $audiodata['introduction_audio']?url_add_domainname($audiodata['introduction_audio']):'';
		$this->assign('audiodata',$audiodata);
		$this->assign('uuid',$uuid);
		$this->display();
	}
    //主播备注
	public function user_remark()
    {
        $uuid = I('post.uuid');
        $content = I('post.remark_content');
        $user_info = M('member')->where(['uuid'=>$uuid])->find();
        if($user_info){
            $add_remark['user_id'] = $uuid;
            $add_remark['content'] = $content;
            $add_remark['add_time'] = date('Y-m-d H:i:s',time());
            $add_remark['admin_id'] = urlsafe_b64decode(cookie("heardadminData"));
            M('userremark')->add($add_remark);
            $this->adminlog("主播".$uuid."添加备注");
			$from = I('post.from');
			if($from == 'selectreview_message'){
				$this->success('备注成功',"/Home/User/selectreview_list",1);
			}else{
				$this->success('备注成功',"/Home/User/user_list",1);
			}

        }else{
            $this->error('主播不存',"",1);
        }
    }
    //主播备注列表
    public function user_remark_list()
    {
        $db_member = M('member m');
        $this->p = I('get.p')?I('get.p'):1;
        $user_name = I('get.user_name');
        $this->user_name = $user_name;
        $where = '1=1';
        if (!empty($user_name)) {$where .= " and (nickname like '%$user_name%' or uuid like '%$user_name%')";}
        $count = $db_member->where(array('status'=>9))->where($where)->join('db_userremark ur on m.uuid = ur.user_id')->count();
        $p = getpage($count, 20);
        $remark_lsit = $db_member
            ->field('ur.id,m.uuid,m.nickname,ur.content,ur.add_time,a.heard_adminname as admin_name')
            ->where(array('status'=>9))->where($where)
            ->join('db_userremark ur on m.uuid = ur.user_id')
			->join('__ADMIN__ a on a.heard_admin_id = ur.admin_id','left')
            ->limit($p->firstRow, $p->listRows)
			->order('ur.id desc')
            ->select();
        $page = $p->show();
        $map['user_name'] = empty($user_name)?"":$user_name;
        $p->parameter = "";
        foreach($map as $key=>$val) {
            $p->parameter .= "$key=".urlencode($val)."&";
        }
        $this->assign('remark_lsit',$remark_lsit);
        $this->assign('page', $page);
        $this->display();
    }
}